this.BX=this.BX||{};this.BX.UI=this.BX.UI||{};(function(e,t){"use strict";var i=function(){function e(i,a){babelHelpers.classCallCheck(this,e);this.progress=false;this.deleted=false;this.setData(i);if(t.Type.isPlainObject(a)){if(t.Type.isString(a.languageId)){this.setLanguageId(a.languageId)}this.moduleId=a.moduleId}this.actions={get:"main.userFieldConfig.get",add:"main.userFieldConfig.add",update:"main.userFieldConfig.update",delete:"main.userFieldConfig.delete"}}babelHelpers.createClass(e,[{key:"load",value:function e(){var i=this;return new Promise((function(e,a){var s=[];if(i.progress){s.push("Another action is in progress");a(s);return}if(!i.isSaved()){s.push("Cant load UserField without id");a(s);return}var n=i.actions.get;if(!t.Type.isString(n)||n.length<=0){s.push("UserField load action is not specified");a(s);return}i.progress=true;t.ajax.runAction(n,{data:{id:i.getId(),moduleId:i.moduleId}}).then((function(t){i.progress=false;i.setData(t.data.field);e(t)}))["catch"]((function(e){i.progress=false;e.errors.forEach((function(e){var t=e.message;s.push(t)}));a(s)}))}))}},{key:"save",value:function e(){var i=this;return new Promise((function(e,a){var s=[];if(i.progress){s.push("Another action is in progress");a(s);return}var n;var r;if(i.isSaved()){n=i.actions.update;r={id:i.getId(),field:i.getData(),moduleId:i.moduleId}}else{n=i.actions.add;r={field:i.getData(),moduleId:i.moduleId}}if(!t.Type.isString(n)||n.length<=0){s.push("UserField action is not specified");a(s);return}i.progress=true;t.ajax.runAction(n,{data:r}).then((function(t){i.progress=false;i.setData(t.data.field);e(t)}))["catch"]((function(e){i.progress=false;e.errors.forEach((function(e){var i=e.message;if(t.Type.isPlainObject(i)&&i.text){s.push(i.text)}else{s.push(i)}}));a(s)}))}))}},{key:"delete",value:function e(){var i=this;return new Promise((function(e,a){var s=[];if(i.progress){s.push("Another action is in progress");a(s);return}if(!i.isSaved()){s.push("Cant delete UserField without id");a(s);return}var n=i.actions["delete"];if(!t.Type.isString(n)||n.length<=0){s.push("UserField action is not specified");a(s);return}i.progress=true;t.ajax.runAction(n,{data:{id:i.getId(),moduleId:i.moduleId}}).then((function(){i.deleted=true;i.progress=false;e()}))["catch"]((function(e){i.progress=false;e.errors.forEach((function(e){var t=e.message;s.push(t)}));a(s)}))}))}},{key:"setLanguageId",value:function e(t){this.languageId=t;return this}},{key:"setModuleId",value:function e(t){this.moduleId=t;return this}},{key:"getLanguageId",value:function e(){if(!this.languageId){return t.Loc.getMessage("LANGUAGE_ID")}return this.languageId}},{key:"getId",value:function e(){return t.Text.toInteger(this.data.id)}},{key:"isSaved",value:function e(){return this.getId()>0}},{key:"setData",value:function e(t){this.data=t;return this}},{key:"getData",value:function e(){return this.data}},{key:"getName",value:function e(){return this.data.fieldName}},{key:"setName",value:function e(t){if(this.isSaved()){console.error("Changing name is not available on saved UserField");return this}this.data.fieldName=t;return this}},{key:"getEntityId",value:function e(){return this.data.entityId}},{key:"getUserTypeId",value:function e(){return this.data.userTypeId}},{key:"setUserTypeId",value:function e(t){if(this.isSaved()){console.error("Changing userTypeId is not available on saved UserField");return this}this.data.userTypeId=t;return this}},{key:"getEnumeration",value:function e(){if(!t.Type.isArray(this.data["enum"])){this.data["enum"]=[]}return this.data["enum"]}},{key:"setEnumeration",value:function e(t){this.data["enum"]=t;return this}},{key:"getTitle",value:function i(){var a=e.getTitleFieldNames();var s=a.length;var n=this.getLanguageId();for(var r=0;r<s;r++){if(this.data[a[r]]&&t.Type.isString(this.data[a[r]][n])&&this.data[a[r]][n].length>0){return this.data[a[r]][n]}}return this.getName()}},{key:"setTitle",value:function e(i,a){if(t.Type.isString(i)&&i.length>0){if(!a){a=this.getLanguageId()}if(!this.data["editFormLabel"]){this.data["editFormLabel"]={}}this.data["editFormLabel"][a]=i;if(this.getUserTypeId()==="boolean"){if(!this.data.settings){this.data.settings={}}this.data.settings.LABEL_CHECKBOX=i}}return this}},{key:"isMultiple",value:function e(){return this.data.multiple==="Y"}},{key:"isMandatory",value:function e(){return this.data.mandatory==="Y"}},{key:"setIsMandatory",value:function e(i){this.data.mandatory=t.Text.toBoolean(i)?"Y":"N"}},{key:"setIsMultiple",value:function e(i){if(this.isSaved()){console.error("Changing multiple is not available on saved UserField");return this}this.data.multiple=t.Text.toBoolean(i)===true?"Y":"N";return this}},{key:"getDetailUrl",value:function e(){return this.data.detailUrl}},{key:"isDeleted",value:function e(){return this.deleted}},{key:"serialize",value:function e(){return JSON.stringify({data:this.data,languageId:this.languageId,moduleId:this.moduleId,progress:this.progress,deleted:this.deleted})}}],[{key:"getTitleFieldNames",value:function e(){return["editFormLabel","listColumnLabel","listFilterLabel"]}},{key:"unserialize",value:function t(i){var a=JSON.parse(i);var s=new e(a.data,{languageId:a.languageId,moduleId:a.moduleId});s.progress=a.progress;s.deleted=a.deleted;return s}}]);return e}();e.UserField=i})(this.BX.UI.UserField=this.BX.UI.UserField||{},BX);
//# sourceMappingURL=userfield.bundle.map.js